package com.blood.modules.pregnancy.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blood.core.config.mybatisplus.ICommonServiceImpl;
import com.blood.core.enums.AbnormalEnum;
import com.blood.core.enums.MessageStatusEnum;
import com.blood.core.enums.PregnancyStatusEnum;
import com.blood.core.enums.RuleEnum;
import com.blood.core.enums.RuleTypeEnum;
import com.blood.core.resp.GlobalResultStatus;
import com.blood.core.resp.PageResult;
import com.blood.core.resp.ResponseResult;
import com.blood.core.util.DateUtil;
import com.blood.core.util.ObjectAssertUtil;
import com.blood.core.util.bean.BeanUtil;
import com.blood.core.util.bean.ListUtils;
import com.blood.core.util.http.RequestTheadUtils;
import com.blood.modules.pregnancy.dto.GatherChartInfo;
import com.blood.modules.pregnancy.dto.GatherInfo;
import com.blood.modules.pregnancy.dto.req.PregnancyAbnormalGatherInfoReq;
import com.blood.modules.pregnancy.dto.req.PregnancyGatherInfoPageReq;
import com.blood.modules.pregnancy.dto.req.PregnancyGatherInfoReq;
import com.blood.modules.pregnancy.dto.req.PregnancyGatherInfoSaveReq;
import com.blood.modules.pregnancy.dto.req.PregnancyGatherOverSaveReq;
import com.blood.modules.pregnancy.dto.resp.*;
import com.blood.modules.pregnancy.mapper.PregnancyGatherInfoMapper;
import com.blood.modules.pregnancy.model.PregnancyGatherInfo;
import com.blood.modules.pregnancy.model.PregnancyMessage;
import com.blood.modules.pregnancy.model.PregnancyRule;
import com.blood.modules.pregnancy.model.PregnancyUser;
import com.blood.modules.pregnancy.service.IPregnancyGatherInfoService;
import com.blood.modules.pregnancy.service.IPregnancyMessageService;
import com.blood.modules.pregnancy.service.IPregnancyRuleService;
import com.blood.modules.pregnancy.service.IPregnancyUserService;
import com.blood.modules.system.service.ISysRoleAuthorityService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;


/**
 * 孕妇信息采集Service业务层处理
 *
 * @author daoren
 * @date 2022-11-25 09:00:10
 */
@Service
public class PregnancyGatherInfoServiceImpl extends ICommonServiceImpl<PregnancyGatherInfoMapper, PregnancyGatherInfo> implements IPregnancyGatherInfoService {
    @Autowired
    private Snowflake snowFlake;
    @Autowired
    private IPregnancyUserService pregnancyUserService;
    @Autowired
    private IPregnancyMessageService pregnancyMessageService;
    @Autowired
    private IPregnancyRuleService pregnancyRuleService;
    @Autowired
    private ISysRoleAuthorityService sysRoleAuthorityService;


    @Override
    public ResponseResult<PageResult<PregnancyGatherListResp>> gatherPageList(PregnancyGatherInfoPageReq req) {
        PageResult<PregnancyGatherListResp> pageResult = PageResult.create(req.getPageNo(), req.getPageSize());
        QueryWrapper<PregnancyGatherInfo> qw = new QueryWrapper<>();
        sysRoleAuthorityService.queryDataAuthority(qw);
        LambdaQueryWrapper<PregnancyGatherInfo> lambda = qw.lambda();
        lambda.eq(PregnancyGatherInfo::getPregnancyId, req.getPregnancyId());
        if (null != req.getDilatancy()) {
            lambda.eq(PregnancyGatherInfo::getDilatancy, req.getDilatancy());
        }
        if (StringUtils.isNotBlank(req.getMedicalSign())) {
            lambda.eq(PregnancyGatherInfo::getMedicalSign, req.getMedicalSign());
        }
        if (null != req.getGatherStart()) {
            lambda.ge(PregnancyGatherInfo::getGatherTime, req.getGatherStart());
        }
        if (null != req.getGatherEnd()) {
            lambda.le(PregnancyGatherInfo::getGatherTime, req.getGatherEnd());
        }
        lambda.eq(PregnancyGatherInfo::isDeleteFlag, false);
        lambda.orderByDesc(PregnancyGatherInfo::getGatherTime);

        IPage<PregnancyGatherInfo> iPage = baseMapper.selectPage(new Page<>(req.getPageNo(), req.getPageSize()), lambda);
        if (iPage.getRecords().size() > 0) {
            List<PregnancyGatherListResp> queryRespList = ListUtils.copyProperties(iPage.getRecords(), PregnancyGatherListResp.class);
            return GlobalResultStatus.SUCCESS.toResult().response(pageResult.data(iPage.getTotal(), queryRespList));
        }
        return GlobalResultStatus.SUCCESS.toResult().response(pageResult.data(0, Collections.emptyList()));
    }

    @Override
    public ResponseResult<PageResult<PregnancyGatherInfoPageResp>> pageList(PregnancyGatherInfoPageReq req) {
        PageResult<PregnancyGatherInfoPageResp> pageResult = PageResult.create(req.getPageNo(), req.getPageSize());
        QueryWrapper<PregnancyGatherInfo> queryWrapper = new QueryWrapper<>();
        sysRoleAuthorityService.queryDataAuthority(queryWrapper);
        LambdaQueryWrapper<PregnancyGatherInfo> qw = queryWrapper.lambda();
        qw.eq(PregnancyGatherInfo::getPregnancyId, req.getPregnancyId());
        if (null != req.getDilatancy()) {
            qw.eq(PregnancyGatherInfo::getDilatancy, req.getDilatancy());
        }
        if (StringUtils.isNotBlank(req.getMedicalSign())) {
            qw.eq(PregnancyGatherInfo::getMedicalSign, req.getMedicalSign());
        }
        if (null != req.getDelStatus()) {
            qw.ge(PregnancyGatherInfo::getDelStatus, req.getDelStatus());
        }
        if (null != req.getGatherStart()) {
            qw.ge(PregnancyGatherInfo::getGatherTime, req.getGatherStart());
        }
        if (null != req.getGatherEnd()) {
            qw.le(PregnancyGatherInfo::getGatherTime, req.getGatherEnd());
        }
        qw.in(PregnancyGatherInfo::getAbnormalStatus, PregnancyStatusEnum.getAbnormalStatusList());
        qw.eq(PregnancyGatherInfo::isDeleteFlag, false);
        qw.orderByDesc(PregnancyGatherInfo::getGatherTime);

        IPage<PregnancyGatherInfo> iPage = baseMapper.selectPage(new Page<>(req.getPageNo(), req.getPageSize()), qw);
        if (iPage.getRecords().size() > 0) {
            List<PregnancyGatherInfoPageResp> queryRespList = ListUtils.copyProperties(iPage.getRecords(), PregnancyGatherInfoPageResp.class);
            return GlobalResultStatus.SUCCESS.toResult().response(pageResult.data(iPage.getTotal(), queryRespList));
        }
        return GlobalResultStatus.SUCCESS.toResult().response(pageResult.data(0, Collections.emptyList()));
    }

    @Override
    public List<PregnancyGatherInfo> queryList(List<String> pregnancyIdList) {
        QueryWrapper<PregnancyGatherInfo> queryWrapper = new QueryWrapper<>();
        sysRoleAuthorityService.queryDataAuthority(queryWrapper);
        return baseMapper.selectList(queryWrapper
                .select("pregnancy_id", "abnormal_status", "count(abnormal_status) as number")
                .lambda()
                .in(PregnancyGatherInfo::getPregnancyId, pregnancyIdList)
                .eq(PregnancyGatherInfo::isDeleteFlag, false)
                .groupBy(PregnancyGatherInfo::getPregnancyId, PregnancyGatherInfo::getAbnormalStatus))
                ;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult<PregnancyGatherSaveResp> saveInfo(PregnancyGatherInfoSaveReq req) {
        //查询孕妇信息
        PregnancyUser pregnancyUser = pregnancyUserService.findById(req.getPregnancyId());
        ObjectAssertUtil.objectIsNull(pregnancyUser, "孕妇信息不存在!");
        ObjectAssertUtil.isBoolean(PregnancyStatusEnum.DISCHARGED.getValue().equals(pregnancyUser.getStatus()), "孕妇已完结，不可采集！");
        String id = snowFlake.nextIdStr();
        PregnancyGatherInfo saveInfo = new PregnancyGatherInfo();
        BeanUtil.copyProperties(req, saveInfo);
        saveInfo.setId(id);
        saveInfo.setAbnormalStatus(PregnancyStatusEnum.NORMAL.getValue());
        setGatherInfo(req, pregnancyUser, saveInfo);
        baseMapper.insert(saveInfo);
        PregnancyGatherSaveResp resp = new PregnancyGatherSaveResp();
        resp.setAbnormalFlag(!PregnancyStatusEnum.NORMAL.getValue().equals(saveInfo.getAbnormalStatus()));
        resp.setGatherId(saveInfo.getId());
        return GlobalResultStatus.SUCCESS.toResult().response(resp);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult<Void> revocation(String gatherId) {
        PregnancyGatherInfo gatherInfo = findById(gatherId);
        ObjectAssertUtil.objectIsNull(gatherInfo, "采集信息不存在!");
        ObjectAssertUtil.isBoolean(null!=gatherInfo.getProcessTime(), "已处理异常，不可撤销！");

        PregnancyUser pregnancyUser = pregnancyUserService.findById(gatherInfo.getPregnancyId());
        ObjectAssertUtil.objectIsNull(pregnancyUser, "孕妇信息不存在!");
        ObjectAssertUtil.isBoolean(PregnancyStatusEnum.DISCHARGED.getValue().equals(pregnancyUser.getStatus()), "孕妇已完结，不可撤销采集！");
        //删除采集信息
        gatherInfo.setUpdateBy(RequestTheadUtils.getUserId());
        gatherInfo.setDeleteFlag(true);
        baseMapper.updateById(gatherInfo);
        //查询最新一条采集信息
        PregnancyGatherInfo selectOne = baseMapper.selectOne(new QueryWrapper<PregnancyGatherInfo>().lambda()
                .ne(PregnancyGatherInfo::getLineNo, gatherInfo.getLineNo())
                .eq(PregnancyGatherInfo::isDeleteFlag, false)
                .orderByDesc(PregnancyGatherInfo::getGatherTime)
                .last(" limit 1")
        );
        //修改孕产信息
        if (null != selectOne) {
            pregnancyUser.setGatherId(selectOne.getId());
            pregnancyUser.setDecline(selectOne.getDecline());
            pregnancyUser.setDilatancy(selectOne.getDilatancy());
            pregnancyUser.setGatherTime(selectOne.getGatherTime());
        } else {
            pregnancyUser.setGatherId(null);
            pregnancyUser.setDecline(null);
            pregnancyUser.setDilatancy(null);
            pregnancyUser.setGatherTime(null);
        }
        pregnancyUser.setUpdateBy(RequestTheadUtils.getUserId());
        pregnancyUserService.updateById(pregnancyUser);
        //删除通知信息
        pregnancyMessageService.removeInfo(gatherId);
        return GlobalResultStatus.SUCCESS.toResult().responseEmptyBody();
    }

    /**
     * 设置采集信息
     *
     * @param req           请求参数
     * @param pregnancyUser 孕妇信息
     * @param saveInfo      保存修改信息
     */
    private void setGatherInfo(PregnancyGatherInfoSaveReq req, PregnancyUser pregnancyUser, PregnancyGatherInfo saveInfo) {
        saveInfo.setDoctorId(StringUtils.isNotBlank(req.getDoctorId()) ? req.getDoctorId() : pregnancyUser.getDoctorId());
        saveInfo.setCreateBy(RequestTheadUtils.getUserId());
        saveInfo.setOrgId(RequestTheadUtils.getOrgId());
        //规则验证检验异常
        ruleCheck(pregnancyUser, saveInfo);
        //表格异常录入
        if (null != req.getAbnormal() && !AbnormalEnum.NOT.getValue().equals(req.getAbnormal())) {
            if (PregnancyStatusEnum.NORMAL.getValue().equals(saveInfo.getAbnormalStatus())) {
                saveInfo.setAbnormalStatus(PregnancyStatusEnum.EARLY.getValue());
            }
            if (AbnormalEnum.UC.getValue().equals(req.getAbnormal())) {
                if (StringUtils.isBlank(saveInfo.getAbnormalCause())) {
                    saveInfo.setAbnormalCause(AbnormalEnum.UC.getName());
                } else {
                    saveInfo.setAbnormalCause(saveInfo.getAbnormalCause() + "、" + AbnormalEnum.UC.getName());
                }
            }
            if (AbnormalEnum.OTHER.getValue().equals(req.getAbnormal())) {
                if (StringUtils.isBlank(saveInfo.getAbnormalCause())) {
                    saveInfo.setAbnormalCause(saveInfo.getAbnormalRemake());
                } else {
                    saveInfo.setAbnormalCause(saveInfo.getAbnormalCause() + "、" + saveInfo.getAbnormalRemake());
                }
            }
        }
        if (PregnancyStatusEnum.getAbnormalStatusList().contains(saveInfo.getAbnormalStatus())) {
            pregnancyUser.setStatus(saveInfo.getAbnormalStatus());
        }
        //异常通知，不是主治医生采集信息添加代办通知
        if (PregnancyStatusEnum.getAbnormalStatusList().contains(saveInfo.getAbnormalStatus()) && StringUtils.isNotBlank(saveInfo.getDoctorId()) && !saveInfo.getDoctorId().equals(RequestTheadUtils.getUserId())) {
            PregnancyMessage message = new PregnancyMessage();
            message.setType(MessageStatusEnum.DIS_ENABLE.getValue());
            message.setGatherId(saveInfo.getId());
            message.setPregnancyId(saveInfo.getPregnancyId());
            message.setGatherId(saveInfo.getId());
            message.setPregnancyName(pregnancyUser.getName());
            message.setOrgId(saveInfo.getOrgId());
            message.setCreateBy(saveInfo.getCreateBy());
            message.setIntro(saveInfo.getAbnormalCause());
            message.setDes(saveInfo.getAbnormalRemake());
            message.setSendId(saveInfo.getCreateBy());
            message.setTitle(PregnancyStatusEnum.find(saveInfo.getAbnormalStatus()).getName());
            message.setReceiveId(saveInfo.getDoctorId());
            pregnancyMessageService.saveInfo(message);
        }

        //修改孕妇信息
        pregnancyUser.setDoctorId(saveInfo.getDoctorId());
        boolean setUserInfo = null == pregnancyUser.getGatherTime() || (null != pregnancyUser.getGatherTime() && pregnancyUser.getGatherTime().getTime() <= saveInfo.getGatherTime().getTime());
        if (setUserInfo) {
            pregnancyUser.setGatherId(saveInfo.getId());
            pregnancyUser.setGatherTime(saveInfo.getGatherTime());
            pregnancyUser.setDilatancy(saveInfo.getDilatancy());
            pregnancyUser.setDecline(saveInfo.getDecline());
        }
        if (null != req.getSystolicPressure() && null != req.getDiastolicPressure()) {
            saveInfo.setBloodPressure(req.getSystolicPressure() + "/" + req.getDiastolicPressure() + " mmHg");
        }
        pregnancyUser.setStatus(saveInfo.getAbnormalStatus());
        pregnancyUser.setUpdateBy(RequestTheadUtils.getUserId());
        pregnancyUserService.updateById(pregnancyUser);
        //保存采集信息
        saveInfo.setAbnormalRemake(req.getAbnormalRemake());
    }


    @Override
    public ResponseResult<PregnancyGatherResp> getAbnormalInfo(String gatherId) {
        PregnancyGatherInfo gatherInfo = findById(gatherId);
        ObjectAssertUtil.objectIsNull(gatherInfo, "异常信息不存在！");
        //查询孕妇信息
        PregnancyUser pregnancyUser = pregnancyUserService.findById(gatherInfo.getPregnancyId());
        ObjectAssertUtil.objectIsNull(pregnancyUser, "孕妇信息不存在!");
        PregnancyGatherResp resp = new PregnancyGatherResp();
        resp.setAbnormalFlag(true);
        setGatherInfo(gatherInfo, resp);
        resp.setTotalTime(gatherInfo.getTotalTime());
        resp.setDecline(gatherInfo.getDecline());
        resp.setDilatancy(gatherInfo.getDilatancy());
        resp.setPregnancyId(gatherInfo.getPregnancyId());
        resp.setGatherId(gatherInfo.getId());
        resp.setDoctorId(pregnancyUser.getDoctorId());
        resp.setAbnormalCause(gatherInfo.getAbnormalCause());
        resp.setAbnormalMedicalId(gatherInfo.getAbnormalMedicalId());
        resp.setAbnormalMedicalSign(gatherInfo.getAbnormalMedicalSign());
        resp.setProcessMode(gatherInfo.getProcessMode());
        resp.setMayCauseInfo(ListUtils.copyProperties(pregnancyRuleService.queryList(RuleTypeEnum.DISPOSE.getValue()), PregnancyRuleInfoResp.class));
        return GlobalResultStatus.SUCCESS.toResult().response(resp);
    }

    private void setGatherInfo(PregnancyGatherInfo gatherInfo, PregnancyGatherResp resp) {
        QueryWrapper<PregnancyGatherInfo> qw = new QueryWrapper<>();
        sysRoleAuthorityService.queryDataAuthority(qw);
        LambdaQueryWrapper<PregnancyGatherInfo> queryWrapper = qw.lambda()
                .eq(PregnancyGatherInfo::getPregnancyId, gatherInfo.getPregnancyId());
        if (null != gatherInfo.getGatherTime()) {
            queryWrapper.lt(PregnancyGatherInfo::getGatherTime, gatherInfo.getGatherTime());
        }
        PregnancyGatherInfo LastGatherInfo = baseMapper.selectOne(queryWrapper
                .eq(PregnancyGatherInfo::isDeleteFlag, false)
                .orderByDesc(PregnancyGatherInfo::getGatherTime)
                .last("limit 1"));
        if (null != LastGatherInfo) {
            resp.setLastDecline(gatherInfo.getDecline());
            resp.setLastDilatancy(gatherInfo.getDilatancy());
            resp.setDeclineStatus(gatherInfo.getDecline() > LastGatherInfo.getDecline() ? 1 : gatherInfo.getDecline() < LastGatherInfo.getDecline() ? -1 : 0);
            resp.setDilatancyStatus(gatherInfo.getDilatancy() > LastGatherInfo.getDilatancy() ? 1 : gatherInfo.getDilatancy() < LastGatherInfo.getDilatancy() ? -1 : 0);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult<Void> delAdd(PregnancyAbnormalGatherInfoReq req) {
        PregnancyGatherInfo gatherInfo = findById(req.getId());
        ObjectAssertUtil.objectIsNull(gatherInfo, "采集信息不存在!");
        ObjectAssertUtil.isBoolean(null != gatherInfo.getProcessTime(),"已处理，不可重复处理！");
        //查询孕妇信息
        PregnancyUser pregnancyUser = pregnancyUserService.findById(gatherInfo.getPregnancyId());
        ObjectAssertUtil.objectIsNull(pregnancyUser, "孕妇信息不存在!");
        ObjectAssertUtil.isBoolean(PregnancyStatusEnum.DISCHARGED.getValue().equals(pregnancyUser.getStatus()), "孕妇已完结，无需处理！");

        //处理信息
        PregnancyGatherInfo saveInfo = new PregnancyGatherInfo();
        BeanUtil.copyProperties(req, saveInfo);
        saveInfo.setUpdateBy(RequestTheadUtils.getUserId());
        //查询是否还有未处理的异常信息
        PregnancyGatherInfo oldGatherInfo = baseMapper.selectOne(new LambdaQueryWrapper<PregnancyGatherInfo>()
                .ne(PregnancyGatherInfo::getId, saveInfo.getId())
                .isNull(PregnancyGatherInfo::getProcessTime)
                .in(PregnancyGatherInfo::getAbnormalStatus, PregnancyStatusEnum.getAbnormalStatusList())
                .eq(PregnancyGatherInfo::isDeleteFlag, false)
                .last("limit 1"));
        if (null == oldGatherInfo && !pregnancyUser.getStatus().equals(PregnancyStatusEnum.DISCHARGED.getValue())) {
            pregnancyUser.setStatus(PregnancyStatusEnum.NORMAL.getValue());
        }
        saveInfo.setProcessTime(new Date());
        saveInfo.setDelStatus(MessageStatusEnum.DIS_ENABLE.getValue());
        updateById(saveInfo, req.getId());
        //采集信息添加通知
        PregnancyMessage message = new PregnancyMessage();
        message.setGatherId(saveInfo.getId());
        message.setReceiveId(saveInfo.getDoctorId());
        if (StringUtils.isNotBlank(gatherInfo.getDoctorId()) && !gatherInfo.getDoctorId().equals(RequestTheadUtils.getUserId())) {
            message.setPregnancyId(pregnancyUser.getId());
            message.setGatherId(saveInfo.getId());
            message.setPregnancyName(pregnancyUser.getName());
            message.setOrgId(RequestTheadUtils.getOrgId());
            message.setCreateBy(RequestTheadUtils.getUserId());
            message.setIntro(gatherInfo.getAbnormalCause());
            message.setDes(StringUtils.isNotBlank(gatherInfo.getAbnormalRemake()) ? gatherInfo.getAbnormalRemake() : gatherInfo.getAbnormalCause());
            message.setSendId(RequestTheadUtils.getUserId());
            message.setReceiveId(gatherInfo.getDoctorId());
            message.setTitle("处理异常");
            message.setDisStatus(MessageStatusEnum.DIS_ENABLE.getValue());
            pregnancyMessageService.saveInfo(message);
        }
        //修改处理异常
        pregnancyMessageService.updateInfo(message);
        pregnancyUserService.updateById(pregnancyUser);
        return GlobalResultStatus.SUCCESS.toResult().responseEmptyBody();
    }

    @Override
    public ResponseResult<Void> overAdd(PregnancyGatherOverSaveReq req) {
        //查询孕妇信息
        PregnancyUser pregnancyUser = pregnancyUserService.findById(req.getPregnancyId());
        ObjectAssertUtil.objectIsNull(pregnancyUser, "孕妇信息不存在!");
        //修改孕妇状态
        PregnancyUser user = new PregnancyUser();
        user.setStatus(PregnancyStatusEnum.DISCHARGED.getValue());
        user.setUpdateBy(RequestTheadUtils.getUserId());
        pregnancyUserService.updateById(user, pregnancyUser.getId());
        //完结信息添加通知
        if (!pregnancyUser.getDoctorId().equals(RequestTheadUtils.getUserId())) {
            PregnancyMessage message = new PregnancyMessage();
            message.setReceiveId(pregnancyUser.getDoctorId());
            message.setPregnancyId(pregnancyUser.getId());
            message.setPregnancyName(pregnancyUser.getName());
            message.setOrgId(RequestTheadUtils.getOrgId());
            message.setCreateBy(RequestTheadUtils.getUserId());
            message.setIntro("采集完结");
            message.setSendId(RequestTheadUtils.getUserId());
            message.setReceiveId(pregnancyUser.getDoctorId());
            message.setTitle("完结");
            message.setDisStatus(MessageStatusEnum.DIS_ENABLE.getValue());
            pregnancyMessageService.saveInfo(message);
        }
        //修改代办
        pregnancyMessageService.batchUpdateInfo(pregnancyUser.getId());
        return GlobalResultStatus.SUCCESS.toResult().responseEmptyBody();
    }


    @Override
    public ResponseResult<PregnancyGatherInfoResp> getInfo(PregnancyGatherInfoReq req) {
        PregnancyGatherInfoResp resp = new PregnancyGatherInfoResp();
        GatherInfo respInfo = getRespInfo(req.getPregnancyId(), resp);
        resp.setPregnancyGatherList(respInfo.getGatherList());
        resp.setUnDisGatherIdList(respInfo.getUnDisGatherIdList());
        return GlobalResultStatus.SUCCESS.toResult().response(resp);
    }


    @Override
    public ResponseResult<PregnancyGatherDetailInfoResp> findDetailById(String id) {
        PregnancyGatherDetailInfoResp resp = new PregnancyGatherDetailInfoResp();
        getRespInfo(id, resp);
        return GlobalResultStatus.SUCCESS.toResult().response(resp);
    }


    /**
     * 规矩预警处理
     *
     * @param pregnancyUser 孕妇信息
     * @param saveInfo      采集保存信息
     */
    private void ruleCheck(PregnancyUser pregnancyUser, PregnancyGatherInfo saveInfo) {
        double threeDouble = 3.00;
        double nine = 9.00;
        double ten = 10.00;
        long eightLone = 8L;
        long sixLone = 16L;
        long sixTenLong = 60L;
        long twoLong = 120L;
        String abnormalRemake = saveInfo.getAbnormalRemake();
        //查询历史采集
        LambdaQueryWrapper<PregnancyGatherInfo> queryWrapper = new QueryWrapper<PregnancyGatherInfo>().select("dilatancy", "decline", "gather_time", "septal").lambda()
                .in(PregnancyGatherInfo::getPregnancyId, pregnancyUser.getId())
                .le(PregnancyGatherInfo::getGatherTime, saveInfo.getGatherTime());
        if (null != saveInfo.getLineNo()) {
            queryWrapper.ne(PregnancyGatherInfo::getLineNo, saveInfo.getLineNo());
        }
        List<PregnancyGatherInfo> gatherInfoList = baseMapper.selectList(queryWrapper
                .eq(PregnancyGatherInfo::isDeleteFlag, false)
                .orderByAsc(PregnancyGatherInfo::getGatherTime));
        //设置累计时间
        if (gatherInfoList.size() == 0) {
            saveInfo.setTotalTime(DateUtil.defaultTime);
        } else {
            saveInfo.setTotalTime(DateUtil.dateDiff(gatherInfoList.get(gatherInfoList.size() - 1).getGatherTime(), saveInfo.getGatherTime()));
        }
        gatherInfoList.add(saveInfo);
        if (gatherInfoList.size() > 1) {
            List<PregnancyRule> ruleList = pregnancyRuleService.queryList(RuleTypeEnum.Rule.getValue());
            for (PregnancyRule rule : ruleList) {
                if (RuleEnum.LURK_EXTEND_RULE.getValue().equals(rule.getTag())) {
                    //初产妇>20小时，经产妇>14小时
                    Date startTime = gatherInfoList.stream().filter(f -> f.getDilatancy() < threeDouble).findFirst().orElse(new PregnancyGatherInfo()).getGatherTime();
                    if (null != startTime) {
                        Date endTime = null;
                        List<PregnancyGatherInfo> collect = gatherInfoList.stream().filter(f -> f.getDilatancy() >= threeDouble).collect(Collectors.toList());
                        if (CollectionUtil.isEmpty(collect) && saveInfo.getDilatancy() >= threeDouble) {
                            endTime = saveInfo.getGatherTime();
                        }
                        if (null != endTime) {
                            long dateMinute = DateUtil.dateMinute(startTime, endTime);
                            if ((pregnancyUser.getPluripara()==1&&dateMinute > 1200L)||(pregnancyUser.getPluripara()==2&&dateMinute>14*60L)) {
                                setRuleMessage(saveInfo, rule, PregnancyStatusEnum.EARLY, abnormalRemake);
                            }
                        }
                    }
                } else if (RuleEnum.PROLONGED_ACTIVE_PHASE_RULE.getValue().equals(rule.getTag())) {
                    //活跃期宫颈口扩张速度<0.5cm/h
                    if (saveInfo.getDilatancy() >= threeDouble && saveInfo.getDilatancy() <= ten) {
                        PregnancyGatherInfo start = null;
                        for (PregnancyGatherInfo pregnancyGatherInfo : gatherInfoList) {
                            if (pregnancyGatherInfo.getDilatancy() >= threeDouble && pregnancyGatherInfo.getDilatancy() <= ten) {
                                start = pregnancyGatherInfo;
                                break;
                            }
                        }
                        if (null != start) {
                            //宫颈扩张速度 结束胎头-开始胎头/结束时间-开始时间 （分钟）
                            double decline = saveInfo.getDilatancy() - start.getDilatancy();
                            if (decline == 0) {
                                if (DateUtil.dateMinute(start.getGatherTime(), saveInfo.getGatherTime()) > sixLone) {
                                    setRuleMessage(saveInfo, rule, PregnancyStatusEnum.EARLY, abnormalRemake);
                                }
                            } else {
                                BigDecimal divide = BigDecimal.valueOf(decline)
                                        .divide(BigDecimal.valueOf(DateUtil.dateMinute(start.getGatherTime(), saveInfo.getGatherTime())), 8, BigDecimal.ROUND_DOWN);
                                boolean disInfo = divide
                                        .multiply(BigDecimal.valueOf(sixTenLong)).compareTo(BigDecimal.ONE) == -1;
                                if (disInfo) {
                                    setRuleMessage(saveInfo, rule, PregnancyStatusEnum.EARLY, abnormalRemake);
                                }
                            }

                        }
                    }

                } else if (RuleEnum.PROTRACTED_ACTIVE_PHASE_RULE.getValue().equals(rule.getTag())) {
                    //进入活跃期后宫口不再扩张2小时以上。
                    List<PregnancyGatherInfo> collect = gatherInfoList.stream().filter(f -> f.getDilatancy() >= threeDouble && f.getDilatancy() < ten).sorted(Comparator.comparing(PregnancyGatherInfo::getGatherTime).reversed()).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(collect)) {
                        boolean dis = true;
                        for (PregnancyGatherInfo pregnancyGatherInfo : collect) {
                            long minute = DateUtil.dateMinute(pregnancyGatherInfo.getGatherTime(), saveInfo.getGatherTime());
                            if (minute < twoLong) {
                                dis = false;
                                continue;
                            }

                            if (minute >= twoLong && pregnancyGatherInfo.getDilatancy() < saveInfo.getDilatancy()) {
                                dis = false;
                                break;
                            }
                            if (minute >= twoLong && pregnancyGatherInfo.getDilatancy() >= saveInfo.getDilatancy()) {
                                dis = true;
                                break;
                            }
                        }
                        if (dis) {
                            setRuleMessage(saveInfo, rule, PregnancyStatusEnum.EARLY, abnormalRemake);
                        }

                    }

                } else if (RuleEnum.STOP_RULE.getValue().equals(rule.getTag())) {
                    List<PregnancyGatherInfo> collect = gatherInfoList.stream().filter(f -> f.getDilatancy() >= ten).collect(Collectors.toList());
                    if (collect.size() > 0) {
                        long dateHour = DateUtil.dateHour(collect.get(0).getGatherTime(), saveInfo.getGatherTime());
                        if (pregnancyUser.getEmbryoNumber() == 0 && dateHour >= 2) {
                            setRuleMessage(saveInfo, rule, PregnancyStatusEnum.EARLY, abnormalRemake);
                        }
                        if (pregnancyUser.getEmbryoNumber() > 0 && dateHour >= 1) {
                            setRuleMessage(saveInfo, rule, PregnancyStatusEnum.EARLY, abnormalRemake);
                        }
                    }
                } else if (RuleEnum.PROTRACTED_SECOND_STAGE_RULE.getValue().equals(rule.getTag())) {
                    List<PregnancyGatherInfo> collect = gatherInfoList.stream().filter(f -> f.getDilatancy() >= ten).sorted(Comparator.comparing(PregnancyGatherInfo::getGatherTime).reversed()).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(collect)) {
                        boolean dis = true;
                        for (PregnancyGatherInfo pregnancyGatherInfo : collect) {
                            long minute = DateUtil.dateMinute(pregnancyGatherInfo.getGatherTime(), saveInfo.getGatherTime());
                            if (minute < sixTenLong) {
                                dis = false;
                                continue;
                            }

                            if (minute >= sixTenLong && pregnancyGatherInfo.getDecline() < saveInfo.getDecline()) {
                                dis = false;
                                break;
                            }
                            if (minute >= sixTenLong && pregnancyGatherInfo.getDecline() >= saveInfo.getDecline()) {
                                dis = true;
                                break;
                            }
                        }
                        if (dis) {
                            setRuleMessage(saveInfo, rule, PregnancyStatusEnum.EARLY, abnormalRemake);
                        }

                    }
                } else if (RuleEnum.FETAL_HEAD_SECOND_STAGE_RULE.getValue().equals(rule.getTag())) {


                } else if (RuleEnum.FETAL_HEADED_SECOND_STAGE_RULE.getValue().equals(rule.getTag())) {
                    //第二产成图

                    //胎头停留在原处不下降1小时以上
//                    List<PregnancyGatherInfo> collect = gatherInfoList.stream().filter().sorted(Comparator.comparing(PregnancyGatherInfo::getGatherTime).reversed()).collect(Collectors.toList());
                    boolean dis = true;
//                    for (PregnancyGatherInfo pregnancyGatherInfo : collect) {
//                        long minute = DateUtil.dateMinute(pregnancyGatherInfo.getGatherTime(), saveInfo.getGatherTime());
//                        if (minute < sixTenLong) {
//                            dis = false;
//                            continue;
//                        }
//
//                        if (minute >= sixTenLong && pregnancyGatherInfo.getDecline() < saveInfo.getDecline()) {
//                            dis = false;
//                            break;
//                        }
//                        if (minute >= sixTenLong && pregnancyGatherInfo.getDecline() >= saveInfo.getDecline()) {
//                            dis = true;
//                            break;
//                        }
//                    }
                    if (dis) {
                        setRuleMessage(saveInfo, rule, PregnancyStatusEnum.EARLY, abnormalRemake);
                    }
                }
            }
        }
    }

    /**
     * 设置预警信息
     *
     * @param saveInfo       采集信息
     * @param rule           规则
     * @param risk           风险状态
     * @param abnormalRemake 异常备注
     */
    private void setRuleMessage(PregnancyGatherInfo saveInfo, PregnancyRule rule, PregnancyStatusEnum risk, String abnormalRemake) {
        if (StringUtils.isEmpty(saveInfo.getAbnormalCause())) {
            saveInfo.setAbnormalCause(rule.getName());
        } else {
            saveInfo.setAbnormalCause(saveInfo.getAbnormalCause() + "、" + rule.getName());
        }
        saveInfo.setAbnormalStatus(risk.getValue());
        if (StringUtils.isEmpty(abnormalRemake)) {
            saveInfo.setAbnormalRemake(rule.getDes());
        } else {
            saveInfo.setAbnormalRemake(saveInfo.getAbnormalRemake() + "、" + rule.getDes());
        }
    }

    /**
     * 获取详细信息
     *
     * @param pregnancyId 孕产id
     * @param resp        返回信息
     * @return 图标数据
     */
    private GatherInfo getRespInfo(String pregnancyId, PregnancyGatherInfoFather resp) {
        //查询孕妇信息
        PregnancyUser pregnancyUser = pregnancyUserService.findById(pregnancyId);
        ObjectAssertUtil.objectIsNull(pregnancyUser, "孕妇信息不存在!");
        resp.setPregnancyInfo(BeanUtil.copyProperties(pregnancyUser, PregnancyInfoResp.class));
        //查询历史采集信息
        QueryWrapper<PregnancyGatherInfo> qw = new QueryWrapper<>();
        sysRoleAuthorityService.queryDataAuthority(qw);
        List<PregnancyGatherInfo> gatherInfoList = baseMapper.selectList(qw.lambda()
                .eq(PregnancyGatherInfo::isDeleteFlag, false)
                .eq(PregnancyGatherInfo::getPregnancyId, pregnancyId)
                .orderByAsc(PregnancyGatherInfo::getGatherTime));
        PregnancyChartInfoResp chartInfo = new PregnancyChartInfoResp();
        GatherInfo gatherInfo = new GatherInfo();
        List<Date> xDateList = new ArrayList<>();
        setResInfo(resp, pregnancyUser, gatherInfoList, chartInfo, gatherInfo, xDateList);
        return gatherInfo;
    }

    /**
     * 设置返回信息
     *
     * @param resp           返回参数
     * @param pregnancyUser  用户信息
     * @param gatherInfoList 采集信息
     * @param chartInfo      图表信息
     * @param gatherInfo     中间值
     * @param xDateList      x轴时间集合
     */
    private void setResInfo(PregnancyGatherInfoFather resp, PregnancyUser pregnancyUser, List<PregnancyGatherInfo> gatherInfoList, PregnancyChartInfoResp chartInfo, GatherInfo gatherInfo, List<Date> xDateList) {
        int size = gatherInfoList.size();
        resp.setTotal(size);
        //累计信息
        AtomicInteger normal = new AtomicInteger(0);
        AtomicInteger early = new AtomicInteger(0);
        AtomicInteger risk = new AtomicInteger(0);
        double threeDouble = 3.00;
        double fiveDouble = 5.00;
        double ten = 10.00;
        if (size > 0) {
            List<PregnancyGatherListResp> gatherList = new ArrayList<>(size);
            List<PregnancyChartValueResp> dilatancyList = new ArrayList<>(size);
            List<PregnancyChartValueResp> declineList = new ArrayList<>(size);
            List<String> unDisGatherIdList = new ArrayList<>(size);

            //未设置信息
            GatherChartInfo gatherChartInfo = new GatherChartInfo();
            for (PregnancyGatherInfo pregnancyGatherInfo : gatherInfoList) {
                gatherList.add(BeanUtil.copyProperties(pregnancyGatherInfo, PregnancyGatherListResp.class));
                PregnancyChartValueResp dilatancy = new PregnancyChartValueResp();
                dilatancy.setValue(pregnancyGatherInfo.getDilatancy());
                dilatancy.setDateTime(pregnancyGatherInfo.getGatherTime());
                dilatancyList.add(dilatancy);
                //宫缩开始时间
                if (null == resp.getPregnancyInfo().getDeclineTime() && StringUtils.isNotBlank(pregnancyGatherInfo.getStrength())) {
                    resp.getPregnancyInfo().setDeclineTime(pregnancyGatherInfo.getGatherTime());
                }
                PregnancyChartValueResp decline = new PregnancyChartValueResp();
                decline.setValue(pregnancyGatherInfo.getDecline());
                decline.setDateTime(pregnancyGatherInfo.getGatherTime());
                declineList.add(decline);
                xDateList.add(pregnancyGatherInfo.getGatherTime());
                if (PregnancyStatusEnum.getAbnormalStatusList().contains(pregnancyGatherInfo.getAbnormalStatus()) && StringUtils.isBlank(pregnancyGatherInfo.getAbnormalMedicalSign())) {
                    unDisGatherIdList.add(pregnancyGatherInfo.getId());
                }
                //确认第一次点位
                if (gatherChartInfo.getLurkExtendStart()) {
                    checkValue(pregnancyGatherInfo, chartInfo, gatherChartInfo, threeDouble, fiveDouble, ten);
                }
                if (null != resp.getPregnancyInfo().getDeclineTime() && StringUtils.isNotBlank(pregnancyGatherInfo.getStrength())) {
                    resp.getPregnancyInfo().setDeclineTime(pregnancyGatherInfo.getGatherTime());
                }
                if (PregnancyStatusEnum.NORMAL.getValue().equals(pregnancyGatherInfo.getAbnormalStatus())) {
                    normal.addAndGet(1);
                }
                if (PregnancyStatusEnum.EARLY.getValue().equals(pregnancyGatherInfo.getAbnormalStatus())) {
                    early.addAndGet(1);
                }
                if (PregnancyStatusEnum.RISK.getValue().equals(pregnancyGatherInfo.getAbnormalStatus())) {
                    risk.addAndGet(1);
                }
            }
            //设置图表信息
            setGatherInfo(gatherInfoList, chartInfo, xDateList, threeDouble, fiveDouble, ten, dilatancyList, declineList, gatherChartInfo);
            //设置累计时间
            Date endDate;
            if (PregnancyStatusEnum.DISCHARGED.getValue().equals(pregnancyUser.getStatus())) {
                endDate = gatherInfoList.get(gatherInfoList.size() - 1).getGatherTime();
            } else {
                endDate = new Date();
            }
            resp.setTotalTime(DateUtil.dateDiff(gatherInfoList.get(0).getGatherTime(), endDate));
            gatherInfo.setUnDisGatherIdList(unDisGatherIdList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()));
            gatherInfo.setGatherList(gatherList.stream()
                    .sorted(Comparator.comparing(PregnancyGatherListResp::getGatherTime).reversed())
                    .collect(Collectors.toList()));
        } else {
            resp.setTotalTime(DateUtil.defaultTime);
            gatherInfo.setGatherList(Collections.emptyList());
            gatherInfo.setUnDisGatherIdList(Collections.emptyList());
            //默认产程图信息
            Date date = new Date();
            chartInfo.setLurkExtendStart(date);
            xDateList.add(chartInfo.getLurkExtendStart());
        }

        Date date = xDateList.get(xDateList.size() - 1);
        int add = 10;
        if (null != chartInfo.getProlongedStart()) {
            add = null != chartInfo.getRiskEnd().getDateTime() && chartInfo.getRiskEnd().getDateTime().getTime() > chartInfo.getProlongedStart().getTime() ? 0 : 2;
        } else if (null != chartInfo.getThree()) {
            add = 4;
        }

        resp.setNormal(normal.get());
        resp.setEarly(early.get());
        resp.setRisk(risk.get());

        xDateList.add(DateUtil.getAddHour(add, date));
        List<Date> collect = xDateList.stream().distinct().sorted().collect(Collectors.toList());
        chartInfo.setXData(collect);
        resp.setChartInfo(chartInfo);
    }


    /**
     * 设置图表信息
     *
     * @param gatherInfoList  采集信息
     * @param chartInfo       图表信息
     * @param xDateList       x轴
     * @param threeDouble     3cm分界线
     * @param fiveDouble      5cm分界线
     * @param ten             10cm分界线
     * @param dilatancyList   宫口扩张集合
     * @param declineList     胎头下降集合
     * @param gatherChartInfo 图表设置参数标识
     */
    private void setGatherInfo(List<PregnancyGatherInfo> gatherInfoList, PregnancyChartInfoResp chartInfo, List<Date> xDateList, double threeDouble, double fiveDouble, double ten, List<PregnancyChartValueResp> dilatancyList, List<PregnancyChartValueResp> declineList, GatherChartInfo gatherChartInfo) {
        if (gatherChartInfo.getThree() && null == chartInfo.getThree()) {
            Date date = setBoundary(gatherInfoList, xDateList, threeDouble);
            chartInfo.setThree(date);
            chartInfo.setLurkExtendEnd(date);
        }
        if (gatherChartInfo.getFive() && null == chartInfo.getFive()) {
            chartInfo.setFive(setBoundary(gatherInfoList, xDateList, fiveDouble));
        }

        if (gatherChartInfo.getProlongedStart() && null == chartInfo.getProlongedStart()) {
            chartInfo.setProlongedStart(setBoundary(gatherInfoList, xDateList, ten));
        }
        if (null != chartInfo.getProlongedStart()) {
            List<PregnancyGatherInfo> collect = gatherInfoList.stream().filter(f -> f.getDilatancy() >= threeDouble && f.getDilatancy() < ten).collect(Collectors.toList());
            if (collect.size() >= 2) {
                chartInfo.getEarlyStart().setDateTime(collect.get(0).getGatherTime());
                chartInfo.getEarlyStart().setValue(collect.get(0).getDilatancy());
                chartInfo.getEarlyEnd().setDateTime(chartInfo.getProlongedStart());
                chartInfo.getEarlyEnd().setValue(ten);
                setRiskInfo(chartInfo, xDateList);
            }

        }
        chartInfo.setDeclineList(declineList);
        chartInfo.setDilatancyList(dilatancyList);
    }

    /**
     * 获取分界线时间
     *
     * @param gatherInfoList
     * @param xDateList      x轴
     * @param site           分界位置
     */
    private Date setBoundary(List<PregnancyGatherInfo> gatherInfoList, List<Date> xDateList, double site) {
        PregnancyGatherInfo endInfo = gatherInfoList.stream().filter(f -> f.getDilatancy() >= site).findFirst().orElse(null);
        Date res = null;
        if (null != endInfo) {
            if (endInfo.getDilatancy() == site) {
                res = endInfo.getGatherTime();
            } else {
                PregnancyGatherInfo startInfo = gatherInfoList.stream()
                        .sorted(Comparator.comparing(PregnancyGatherInfo::getGatherTime).reversed())
                        .filter(f -> f.getGatherTime().getTime() <= endInfo.getGatherTime().getTime() && !f.getLineNo().equals(endInfo.getLineNo())).findFirst().orElse(null);
                if (null != startInfo) {
                    res = getDate(startInfo, site, endInfo, startInfo);
                    xDateList.add(res);
                }
            }
        }
        return res;
    }

    /**
     * 设置警戒和异常线
     *
     * @param chartInfo
     * @param xDate
     */
    private void setRiskInfo(PregnancyChartInfoResp chartInfo, List<Date> xDate) {
        //异常线
        chartInfo.getRiskStart().setDateTime(DateUtil.getAddHour(4, chartInfo.getEarlyStart().getDateTime()));
        chartInfo.getRiskStart().setValue(chartInfo.getEarlyStart().getValue());
        xDate.add(chartInfo.getRiskStart().getDateTime());

        chartInfo.getRiskEnd().setDateTime(DateUtil.getAddHour(4, chartInfo.getEarlyEnd().getDateTime()));
        chartInfo.getRiskEnd().setValue(10.00);
        xDate.add(chartInfo.getRiskEnd().getDateTime());
    }

    /**
     * 计算差值
     *
     * @param startInfo 开始位置
     * @param site      计算位置
     * @param endInfo   结束时间
     * @param addSite   添加位置
     * @return
     */
    private Date getDate(PregnancyGatherInfo startInfo, double site, PregnancyGatherInfo endInfo, PregnancyGatherInfo addSite) {
        double dilatancy = endInfo.getDilatancy() - startInfo.getDilatancy();
        double zero = 0.00;
        if (dilatancy < zero) {
            dilatancy = -dilatancy;
        }
        //无变化，取一半时间
        if (dilatancy == zero) {
            Date date = new Date(BigDecimal.valueOf(endInfo.getGatherTime().getTime() - startInfo.getGatherTime().getTime())
                    .divide(BigDecimal.valueOf(2), 0, BigDecimal.ROUND_DOWN).add(BigDecimal.valueOf(addSite.getGatherTime().getTime())).longValue());
            return date;
        }
        double lastInfoDilatancy = site - startInfo.getDilatancy();
        if (lastInfoDilatancy < zero) {
            lastInfoDilatancy = -lastInfoDilatancy;
        }
        Date date = new Date(BigDecimal.valueOf(endInfo.getGatherTime().getTime() - startInfo.getGatherTime().getTime())
                .divide(BigDecimal.valueOf(dilatancy), 0, BigDecimal.ROUND_DOWN)
                .multiply(BigDecimal.valueOf(lastInfoDilatancy)).add(BigDecimal.valueOf(addSite.getGatherTime().getTime())).longValue());
        return date;
    }

    /**
     * 根据初次采集确定产程图点位图
     *
     * @param pregnancyGatherInfo
     * @param chartInfo
     * @param gatherChartInfo
     * @return
     */
    private GatherChartInfo checkValue(PregnancyGatherInfo pregnancyGatherInfo, PregnancyChartInfoResp chartInfo, GatherChartInfo gatherChartInfo, double threeDouble, double fiveDouble, double ten) {
        if (pregnancyGatherInfo.getDilatancy() < threeDouble) {
            gatherChartInfo.setLurkExtendStart(false);
            chartInfo.setLurkExtendStart(pregnancyGatherInfo.getGatherTime());
            return gatherChartInfo;
        }
        if (pregnancyGatherInfo.getDilatancy() == threeDouble) {
            gatherChartInfo.setLurkExtendStart(false);
            gatherChartInfo.setLurkExtendEnd(false);
            gatherChartInfo.setThree(false);
            chartInfo.setLurkExtendEnd(pregnancyGatherInfo.getGatherTime());
            chartInfo.setThree(pregnancyGatherInfo.getGatherTime());
            return gatherChartInfo;
        }

        if (pregnancyGatherInfo.getDilatancy() > threeDouble && pregnancyGatherInfo.getDilatancy() < fiveDouble) {
            gatherChartInfo.setLurkExtendStart(false);
            gatherChartInfo.setLurkExtendEnd(false);
            gatherChartInfo.setThree(false);
            chartInfo.setLurkExtendEnd(pregnancyGatherInfo.getGatherTime());
            return gatherChartInfo;
        }
        if (pregnancyGatherInfo.getDilatancy() == fiveDouble) {
            gatherChartInfo.setLurkExtendStart(false);
            gatherChartInfo.setLurkExtendEnd(false);
            gatherChartInfo.setThree(false);
            gatherChartInfo.setFive(false);
            chartInfo.setFive(pregnancyGatherInfo.getGatherTime());
            chartInfo.setLurkExtendEnd(pregnancyGatherInfo.getGatherTime());
            return gatherChartInfo;
        }
        if (pregnancyGatherInfo.getDilatancy() > fiveDouble && pregnancyGatherInfo.getDilatancy() < ten) {
            gatherChartInfo.setLurkExtendStart(false);
            gatherChartInfo.setLurkExtendEnd(false);
            gatherChartInfo.setThree(false);
            gatherChartInfo.setFive(false);
            chartInfo.setLurkExtendEnd(pregnancyGatherInfo.getGatherTime());
            return gatherChartInfo;
        }
        if (pregnancyGatherInfo.getDilatancy() >= ten) {
            gatherChartInfo.setLurkExtendStart(false);
            gatherChartInfo.setLurkExtendEnd(false);
            gatherChartInfo.setThree(false);
            gatherChartInfo.setFive(false);
            gatherChartInfo.setProlongedStart(false);
            chartInfo.setProlongedStart(pregnancyGatherInfo.getGatherTime());
        }
        return gatherChartInfo;
    }
}
